<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="title">
  <span mat-dialog-title>Import properties</span>
  <button mat-icon-button [attr.aria-label]="'Close'" [mat-dialog-close]="">
    <mat-icon class="title__cancel" svgIcon="gio:cancel"> </mat-icon>
  </button>
</div>
<mat-dialog-content [formGroup]="formGroup">
  <span>
    Easily import your API property list. If the properties already exist, their values will be overwritten. If the properties already exist
    and are encrypted, the import will be skipped.
  </span>
  <mat-form-field class="field">
    <textarea matInput formControlName="properties" placeholder='NEW_PROPERTY_KEY="New property value"' rows="10"></textarea>
  </mat-form-field>

  <gio-banner-error *ngIf="formGroup.get('properties').hasError('propertiesFormat')">
    Errors detected in properties filled
    <span gioBannerBody [innerHTML]="formGroup.get('properties').getError('propertiesFormat')"></span>
  </gio-banner-error>
  <gio-banner-warning
    *ngIf="
      formGroup.get('properties').hasError('duplicateKeysReplaced') || formGroup.get('properties').hasError('duplicateKeysNotReplaced')
    "
  >
    Conflicts detected with existing properties
    <span gioBannerBody>
      <div *ngIf="formGroup.get('properties').hasError('duplicateKeysReplaced')">
        {{ formGroup.get('properties').getError('duplicateKeysReplaced') }}
      </div>
      <div *ngIf="formGroup.get('properties').hasError('duplicateKeysNotReplaced')">
        {{ formGroup.get('properties').getError('duplicateKeysNotReplaced') }}
      </div>
    </span>
  </gio-banner-warning>
</mat-dialog-content>

<mat-dialog-actions class="actions" align="end">
  <button mat-button [mat-dialog-close]="">Cancel</button>
  <button
    [class.actions__importInvalid]="formGroup.invalid"
    mat-button
    matTooltip="Import valid properties only!"
    [matTooltipDisabled]="formGroup.valid"
    color="primary"
    type="button"
    (click)="onSave()"
  >
    Import properties
  </button>
</mat-dialog-actions>
